package com.ccll.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccll.domain.po.IpAddress;
import com.ccll.domain.po.LoginRecord;
import com.ccll.mapper.LoginRecordMapper;
import com.ccll.service.LoginRecordService;
import org.springframework.stereotype.Service;

/**
 * @author Seon
 * @date 2022/11/12 18:10
 */
@Service
public class LoginRecordServiceImpl extends ServiceImpl<LoginRecordMapper, LoginRecord> implements LoginRecordService {
    /**
     * 把登录记录进行存库(归属地)
     *
     * @param ipAddress ip属地
     */
    @Override
    public void saveRecordWithIp(IpAddress ipAddress, Long userId) {
        String ownerPlace = ipAddress.getCountry() + "-" + ipAddress.getProvince() + "-" +
                ipAddress.getCity() + "-" + ipAddress.getArea() + "-" + ipAddress.getIsp();
        LoginRecord loginRecord = LoginRecord.builder()
                .address(ownerPlace)
                .ip(ipAddress.getIp())
                .userId(userId)
                .build();
        this.save(loginRecord);
    }
}
